﻿
using KC.Framework.Base;
using KC.Framework.Extension;
using KC.Framework.SecurityHelper;
using System;
using System.Collections.Generic;

namespace KC.Framework.Tenant
{
    /// <summary>
    /// 与租户相关的常量定义
    /// </summary>
    public class TenantConstant
    {
        static TenantConstant()
        {
            #region 默认常量赋值
            DefaultPrivateEncryptKey = string.IsNullOrEmpty(GlobalConfig.EncryptKey)
                ? EncryptPasswordUtil.Key
                : GlobalConfig.EncryptKey;

            DefaultDatabaseConnectionString = string.IsNullOrEmpty(GlobalConfig.DatabaseConnectionString)
                ? "Data Source=localhost;Database=NetCoreAccount;User ID=sa;Password=P@ssw0rd;MultipleActiveResultSets=true;"
                : GlobalConfig.DatabaseConnectionString;

            DefaultStorageConnectionString = string.IsNullOrEmpty(GlobalConfig.StorageConnectionString)
                ? "BlobEndpoint=https://cfwinstorage.blob.core.chinacloudapi.cn/;DefaultEndpointsProtocol=https;AccountName=cfwinstorage;AccountKey=cF0V6oCzMrat9RYDOyRfuVdUKI64x5mOfFipfUzVklho/Y2EEVyZ21Ip3zxYoHrw7U9nuF3wzNt/QvFSH1NIZQ=="
                : GlobalConfig.StorageConnectionString;

            DefaultQueueConnectionString = string.IsNullOrEmpty(GlobalConfig.QueueConnectionString)
                ? "QueueEndpoint=https://cfwinstorage.queue.core.chinacloudapi.cn/;DefaultEndpointsProtocol=https;AccountName=cfwinstorage;AccountKey=cF0V6oCzMrat9RYDOyRfuVdUKI64x5mOfFipfUzVklho/Y2EEVyZ21Ip3zxYoHrw7U9nuF3wzNt/QvFSH1NIZQ=="
                : GlobalConfig.QueueConnectionString;

            DefaultNoSqlConnectionString = string.IsNullOrEmpty(GlobalConfig.NoSqlConnectionString)
                ? "TableEndpoint=https://cfwinstorage.table.core.chinacloudapi.cn/;DefaultEndpointsProtocol=https;AccountName=cfwinstorage;AccountKey=cF0V6oCzMrat9RYDOyRfuVdUKI64x5mOfFipfUzVklho/Y2EEVyZ21Ip3zxYoHrw7U9nuF3wzNt/QvFSH1NIZQ=="
                : GlobalConfig.NoSqlConnectionString;

            DefaultServiceBusConnectionString = string.IsNullOrEmpty(GlobalConfig.ServiceBusConnectionString)
                ? "Endpoint=sb://devcfwin.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=ZaJwd3XnDnswDlgw/NLd/zksQ4P3BnNzMDqLrBRmDFY="
                : GlobalConfig.ServiceBusConnectionString;
            #endregion

            #region 默认连接字符串设置

            var connItem = GetDatabaseConnectionItems();
            var server = connItem.Item1;
            var database = connItem.Item2;
            var password = connItem.Item3;

            var storageItem = GetStorageConnectionItems();
            var endpont = storageItem.Item1;
            var accessName = storageItem.Item2;
            var accessKey = storageItem.Item3;

            var queueItem = GetQueueConnectionItems();
            var queueEndpont = queueItem.Item1;
            var queueName = queueItem.Item2;
            var queueKey = queueItem.Item3;

            var nosqlItem = GetNoSqlConnectionItems();
            var noSqlEndpont = nosqlItem.Item1;
            var noSqlName = nosqlItem.Item2;
            var noSqlKey = nosqlItem.Item3;

            var sblItem = GetServiceBusConnectionItems();
            var serviceBusEndpont = sblItem.Item1;
            var serviceBusName = sblItem.Item2;
            var serviceBusKey = sblItem.Item3;
            #endregion

            var dbaHosts = new List<string> {
                    //本地开发环境：Debug
                    "http://localhost:1003",//com.web.admin
                    "https://localhost:1013",//com.web.admin
                    "http://localhost:1004",//com.webapi.admin
                    "https://localhost:1014",//com.webapi.admin

                    "http://localhost:1005",//com.web.blog
                    "https://localhost:1015",//com.web.blog
                    "http://localhost:1006",//com.webapi.blog
                    "https://localhost:1016",//com.webapi.blog

                    "http://localhost:9009",//com.web.resource
                    "https://localhost:9019",//com.web.resource

                    //本地测试、测试、灰度、正式环境
                    "http://localadmin.kcloudy.com",
                    "http://devadmin.kcloudy.com",
                    "http://testadmin.kcloudy.com",
                    "http://betaadmin.kcloudy.com",
                    "http://admin.kcloudy.com",

                    "http://localblog.kcloudy.com",
                    "http://devblog.kcloudy.com",
                    "http://testblog.kcloudy.com",
                    "http://betablog.kcloudy.com",
                    "http://blog.kcloudy.com",
                };

            //dbaHosts.AddRange(GetTenantHosts(DbaTenantName));

            DbaTenantSignature = new KC.Framework.Base.ServiceRequestToken(DbaTenantId, DbaTenantName, DefaultPrivateEncryptKey).GetEncrptSignature();
            DbaTenantApiAccessInfo = new Tenant()
            {
                TenantId = DbaTenantId,
                TenantName = DbaTenantName,
                TenantDisplayName = DbaTenantDisplayName,
                TenantSignature = DbaTenantSignature,
                PrivateEncryptKey = DefaultPrivateEncryptKey,
                DatabaseType = DefaultDatabaseType,
                Server = server,
                Database = database,
                DatabasePasswordHash = password,
                StorageType = DefaultStorageType,
                StorageEndpoint = endpont,
                StorageAccessName = accessName,
                StorageAccessKeyPasswordHash = accessKey,
                QueueType = DefaultQueueType,
                QueueEndpoint = queueEndpont,
                QueueAccessName = queueName,
                QueueAccessKeyPasswordHash = queueKey,
                NoSqlType = DefaultNoSqlType,
                NoSqlEndpoint = noSqlEndpont,
                NoSqlAccessName = noSqlName,
                NoSqlAccessKeyPasswordHash = noSqlKey,
                DistributedMessageType = DefaultServiceBusType,
                ServiceBusEndpoint = serviceBusEndpont,
                ServiceBusAccessName = serviceBusName,
                ServiceBusAccessKeyPasswordHash = serviceBusKey,
                ContactName = "田长军",
                ContactEmail = "tianchangjun@outlook.com",
                ContactPhone = "13682381319",
                CloudType = DefaultCloudType,
                TenantType = DefaultTenantType,
                Version = DefaultVersion,
                //Hostnames = dbaHosts.ToArray()
            };

            TestTenantSignature = new KC.Framework.Base.ServiceRequestToken(TestTenantId, TestTenantName, DefaultPrivateEncryptKey).GetEncrptSignature();
            TestTenantApiAccessInfo = new Tenant()
            {
                TenantId = TestTenantId,
                TenantName = TestTenantName,
                TenantDisplayName = TestTenantDisplayName,
                TenantSignature = TestTenantSignature,
                PrivateEncryptKey = DefaultPrivateEncryptKey,
                DatabaseType = DefaultDatabaseType,
                Server = server,
                Database = database,
                DatabasePasswordHash = password,
                StorageType = DefaultStorageType,
                StorageEndpoint = endpont,
                StorageAccessName = accessName,
                StorageAccessKeyPasswordHash = accessKey,
                QueueType = DefaultQueueType,
                QueueEndpoint = queueEndpont,
                QueueAccessName = queueName,
                QueueAccessKeyPasswordHash = queueKey,
                NoSqlType = DefaultNoSqlType,
                NoSqlEndpoint = noSqlEndpont,
                NoSqlAccessName = noSqlName,
                NoSqlAccessKeyPasswordHash = noSqlKey,
                DistributedMessageType = DefaultServiceBusType,
                ServiceBusEndpoint = serviceBusEndpont,
                ServiceBusAccessName = serviceBusName,
                ServiceBusAccessKeyPasswordHash = serviceBusKey,
                ContactName = "田长军",
                ContactEmail = "tianchangjun@outlook.com",
                ContactPhone = "13682381319",
                CloudType = DefaultCloudType,
                TenantType = DefaultTenantType,
                Version = DefaultVersion,
                //Hostnames = GetTenantHosts(TestTenantName)
            };

            BuyTenantSignature = new KC.Framework.Base.ServiceRequestToken(BuyTenantId, BuyTenantName, DefaultPrivateEncryptKey).GetEncrptSignature();
            BuyTenantApiAccessInfo = new Tenant()
            {
                TenantId = BuyTenantId,
                TenantName = BuyTenantName,
                TenantDisplayName = BuyTenantDisplayName,
                TenantSignature = BuyTenantSignature,
                PrivateEncryptKey = DefaultPrivateEncryptKey,
                DatabaseType = DefaultDatabaseType,
                Server = server,
                Database = database,
                DatabasePasswordHash = password,
                StorageType = DefaultStorageType,
                StorageEndpoint = endpont,
                StorageAccessName = accessName,
                StorageAccessKeyPasswordHash = accessKey,
                QueueType = DefaultQueueType,
                QueueEndpoint = queueEndpont,
                QueueAccessName = queueName,
                QueueAccessKeyPasswordHash = queueKey,
                NoSqlType = DefaultNoSqlType,
                NoSqlEndpoint = noSqlEndpont,
                NoSqlAccessName = noSqlName,
                NoSqlAccessKeyPasswordHash = noSqlKey,
                DistributedMessageType = DefaultServiceBusType,
                ServiceBusEndpoint = serviceBusEndpont,
                ServiceBusAccessName = serviceBusName,
                ServiceBusAccessKeyPasswordHash = serviceBusKey,
                ContactName = "田长军",
                ContactEmail = "tianchangjun@outlook.com",
                ContactPhone = "13682381319",
                CloudType = DefaultCloudType,
                TenantType = DefaultTenantType,
                Version = DefaultVersion,
                //Hostnames = GetTenantHosts(BuyTenantName)
            };

            SaleTenantSignature = new KC.Framework.Base.ServiceRequestToken(SaleTenantId, SaleTenantName, DefaultPrivateEncryptKey).GetEncrptSignature();
            SaleTenantApiAccessInfo = new Tenant()
            {
                TenantId = SaleTenantId,
                TenantName = SaleTenantName,
                TenantDisplayName = SaleTenantDisplayName,
                TenantSignature = SaleTenantSignature,
                PrivateEncryptKey = DefaultPrivateEncryptKey,
                DatabaseType = DefaultDatabaseType,
                Server = server,
                Database = database,
                DatabasePasswordHash = password,
                StorageType = DefaultStorageType,
                StorageEndpoint = endpont,
                StorageAccessName = accessName,
                StorageAccessKeyPasswordHash = accessKey,
                QueueType = DefaultQueueType,
                QueueEndpoint = queueEndpont,
                QueueAccessName = queueName,
                QueueAccessKeyPasswordHash = queueKey,
                NoSqlType = DefaultNoSqlType,
                NoSqlEndpoint = noSqlEndpont,
                NoSqlAccessName = noSqlName,
                NoSqlAccessKeyPasswordHash = noSqlKey,
                DistributedMessageType = DefaultServiceBusType,
                ServiceBusEndpoint = serviceBusEndpont,
                ServiceBusAccessName = serviceBusName,
                ServiceBusAccessKeyPasswordHash = serviceBusKey,
                ContactName = "田长军",
                ContactEmail = "tianchangjun@outlook.com",
                ContactPhone = "13682381319",
                CloudType = DefaultCloudType,
                TenantType = DefaultTenantType,
                Version = DefaultVersion,
                //Hostnames = GetTenantHosts(SaleTenantName)
            };
        }

        #region 系统相关的常量

        public const CloudType DefaultCloudType = CloudType.Azure;
        public const TenantVersion DefaultVersion = TenantVersion.Standard | TenantVersion.Professional | TenantVersion.Customized;
        public const TenantType DefaultTenantType = TenantType.StoreCredit | TenantType.SupplyChainFinance | TenantType.CommercialFactoring | TenantType.FinanceLease | TenantType.SmallLoan | TenantType.Bank;

        /// <summary>
        /// 域名替换字符串：subdomain
        /// </summary>
        public const string SubDomain = "subdomain";

        public const string ClaimTypes_TenantName = "tenantname";
        #endregion

        #region 租户设置
        
        /// <summary>
        /// 是否开通邮件服务：KC.Enums.Core.ConfigType.EmailConfig = 1
        /// </summary>
        public const string PropertyName_EmailSetting = "EnableEmail";
        /// <summary>
        /// 是否开通短信服务：KC.Enums.Core.ConfigType.SmsConfig = 2
        /// </summary>
        public const string PropertyName_SmsSetting = "EnableSms";
        /// <summary>
        /// 是否开通支付服务：KC.Enums.Core.ConfigType.PaymentMethod = 3
        /// </summary>
        public const string PropertyName_PaymentSetting = "EnablePayment";
        /// <summary>
        /// 是否开通身份认证服务：KC.Enums.Core.ConfigType.ID5 = 4
        /// </summary>
        public const string PropertyName_IDSetting = "EnableId5";
        /// <summary>
        /// 是否开通呼叫中心服务：KC.Enums.Core.ConfigType.CallConfig = 5
        /// </summary>
        public const string PropertyName_CallSetting = "EnableCallCenter";
        /// <summary>
        /// 是否开通物流服务：KC.Enums.Core.ConfigType.LogisticsPlatform = 6
        /// </summary>
        public const string PropertyName_LogisticsSetting = "EnableLogistics";
        /// <summary>
        /// 是否开通微信服务：KC.Enums.Core.ConfigType.WeixinConfig = 7
        /// </summary>
        public const string PropertyName_WeixinSetting = "EnableWeixin";
        /// <summary>
        /// 是否开通电子签章服务：KC.Enums.Core.ConfigType.ContractConfig = 8
        /// </summary>
        public const string PropertyName_ContractSetting = "EnableContract";
        /// <summary>
        /// 是否开通独立域名服务：KC.Enums.Core.ConfigType.OwnDomain = 9
        /// </summary>
        public const string PropertyName_OwnDomainSetting = "EnableOwnDomainName";

        public const string Default_EmailLimit = "10-200-500";
        public const string Default_SmsLimit = "5-50-500";
        public const string Default_PaymentLimit = "1000-5000-100000";
        public const string Default_IDLimit = "5-10-100";
        public const string Default_CallLimit = "10-30-120";
        public const string Default_LogisticsLimit = "10-100-500";
        public const string Default_ContractLimit = "5-20-100";

        #endregion

        #region 测试租户的定义：cDba、cTest、cBug、cSale
        #region Dba: 超级系统客户用例
        public const int DbaTenantId = 1;
        /// <summary>
        /// cDba: 后台管理
        /// </summary>
        public const string DbaTenantName = "cDba";
        public const string DbaTenantDisplayName = "租户管理";
        public static readonly string DbaTenantSignature;
        /// <summary>
        /// Dba's signature to access Webapi
        /// </summary>
        public static Tenant DbaTenantApiAccessInfo { get; private set; }
        #endregion

        #region cTest: 测试租户-核心企业
        public const int TestTenantId = 2;
        /// <summary>
        /// cTest: 测试用户
        /// </summary>
        public const string TestTenantName = "cTest";
        public const string TestTenantDisplayName = "测试租户-核心企业";
        public static readonly string TestTenantSignature;
        /// <summary>
        /// cTest's signature to access Webapi
        /// </summary>
        public static Tenant TestTenantApiAccessInfo { get; private set; }
        #endregion

        #region cBuy: 测试租户-客户
        public const int BuyTenantId = 3;
        /// <summary>
        /// cBuy: 测试租户-客户
        /// </summary>
        public const string BuyTenantName = "cBuy";
        public const string BuyTenantDisplayName = "测试租户-客户";
        public static readonly string BuyTenantSignature;
        /// <summary>
        /// Buy's signature to access Webapi
        /// </summary>
        public static Tenant BuyTenantApiAccessInfo { get; private set; }
        #endregion

        #region cSale: 测试租户-供应商
        public const int SaleTenantId = 4;
        /// <summary>
        ///  cSale: 测试租户-供应商
        /// </summary>
        public const string SaleTenantName = "cSale";
        public const string SaleTenantDisplayName = "测试租户-供应商";
        public static readonly string SaleTenantSignature;
        /// <summary>
        /// Buy's signature to access Webapi
        /// </summary>
        public static Tenant SaleTenantApiAccessInfo { get; private set; }
        #endregion

        #region 获取租户客户端的认知Host列表
        public static string[] GetTenantHosts(string tenantName)
        {
            tenantName = tenantName.ToLower();

            switch(GlobalConfig.SystemType)
            {
                case SystemType.Dev:
                    #region 本地开发环境
                    return new[] {
                    //--------------本地开发环境：调试--------------
                    "http://" + tenantName + ".localhost:1003/",//com.web.admin
                    "https://" + tenantName + ".localhost:1013/",//com.web.admin
                    "http://" + tenantName + ".localhost:1004/",//com.webapi.admin
                    "https://" + tenantName + ".localhost:1014/",//com.webapi.admin
                    //博客管理
                    "http://" + tenantName + ".localhost:1005/",//com.web.blog
                    "https://" + tenantName + ".localhost:1015/",//com.web.blog
                    "http://" + tenantName + ".localhost:1006/",//com.webapi.blog
                    "https://" + tenantName + ".localhost:1016/",//com.webapi.blog
                    //配置管理
                    "http://" + tenantName + ".localhost:1101/",//com.web.config
                    "https://" + tenantName + ".localhost:1111/",//com.web.config
                    "http://" + tenantName + ".localhost:1102/",//com.webapi.config
                    "https://" + tenantName + ".localhost:1112/",//com.webapi.config
                    //字典管理
                    "http://" + tenantName + ".localhost:1103/",//com.web.dict
                    "https://" + tenantName + ".localhost:1113/",//com.web.dict
                    "http://" + tenantName + ".localhost:1104/",//com.webapi.dict
                    "https://" + tenantName + ".localhost:1114/",//com.webapi.dict
                    //应用管理
                    "http://" + tenantName + ".localhost:1105/",//com.web.app
                    "https://" + tenantName + ".localhost:1115/",//com.web.app
                    "http://" + tenantName + ".localhost:1106/",//com.webapi.app
                    "https://" + tenantName + ".localhost:1116/",//com.webapi.app
                    //消息管理
                    "http://" + tenantName + ".localhost:1107/",//com.web.message
                    "https://" + tenantName + ".localhost:1117/",//com.web.message
                    "http://" + tenantName + ".localhost:1108/",//com.webapi.message
                    "https://" + tenantName + ".localhost:1118/",//com.webapi.message
                    
                    //账户管理
                    "http://" + tenantName + ".localhost:2001/",//com.web.account
                    "https://" + tenantName + ".localhost:2011/",//com.web.account
                    "http://" + tenantName + ".localhost:2002/",//com.webapi.account
                    "https://" + tenantName + ".localhost:2012/",//com.webapi.account
                    //合同管理
                    "http://" + tenantName + ".localhost:2003/",//com.web.contract
                    "https://" + tenantName + ".localhost:2013/",//com.web.contract
                    "http://" + tenantName + ".localhost:2004/",//com.webapi.contract
                    "https://" + tenantName + ".localhost:2014/",//com.webapi.contract
                    //文档管理
                    "http://" + tenantName + ".localhost:2005/",//com.web.doc
                    "https://" + tenantName + ".localhost:2015/",//com.web.doc
                    "http://" + tenantName + ".localhost:2006/",//com.webapi.doc
                    "https://" + tenantName + ".localhost:2016/",//com.webapi.doc
                    //人事管理
                    "http://" + tenantName + ".localhost:2007/",//com.web.hr
                    "https://" + tenantName + ".localhost:2017/",//com.web.hr
                    "http://" + tenantName + ".localhost:2008/",//com.webapi.hr
                    "https://" + tenantName + ".localhost:2018/",//com.webapi.hr
                    
                    //客户管理
                    "http://" + tenantName + ".localhost:3001/",//com.web.customer
                    "https://" + tenantName + ".localhost:3011/",//com.web.customer
                    "http://" + tenantName + ".localhost:3002/",//com.webapi.customer
                    "https://" + tenantName + ".localhost:3012/",//com.webapi.customer
                    //供应商管理
                    "http://" + tenantName + ".localhost:3003/",//com.web.supply
                    "https://" + tenantName + ".localhost:3013/",//com.web.supply
                    "http://" + tenantName + ".localhost:3004/",//com.webapi.supply
                    "https://" + tenantName + ".localhost:3014/",//com.webapi.supply
                    //商品管理
                    "http://" + tenantName + ".localhost:3005/",//com.web.product
                    "https://" + tenantName + ".localhost:3015/",//com.web.product
                    "http://" + tenantName + ".localhost:3006/",//com.webapi.product
                    "https://" + tenantName + ".localhost:3016/",//com.webapi.product
                    //物料管理
                    "http://" + tenantName + ".localhost:3007/",//com.web.material
                    "https://" + tenantName + ".localhost:3017/",//com.web.material
                    "http://" + tenantName + ".localhost:3008/",//com.webapi.material
                    "https://" + tenantName + ".localhost:3018/",//com.webapi.material

                    //门户管理
                    "http://" + tenantName + ".localhost:4001/",//com.web.portal
                    "https://" + tenantName + ".localhost:4011/",//com.web.portal
                    "http://" + tenantName + ".localhost:4002/",//com.webapi.portal
                    "https://" + tenantName + ".localhost:4012/",//com.webapi.portal

                    //培训管理
                    "http://" + tenantName + ".localhost:6001/",//com.web.training
                    "https://" + tenantName + ".localhost:6011/",//com.web.training
                    "http://" + tenantName + ".localhost:6002/",//com.webapi.training
                    "https://" + tenantName + ".localhost:6012/",//com.webapi.training

                    //流程管理
                    "http://" + tenantName + ".localhost:7001/",//com.web.workflow
                    "https://" + tenantName + ".localhost:7011/",//com.web.workflow
                    "http://" + tenantName + ".localhost:7002/",//com.webapi.workflow
                    "https://" + tenantName + ".localhost:7012/",//com.webapi.workflow
                    //支付管理
                    "http://" + tenantName + ".localhost:8001/",//com.web.payment
                    "https://" + tenantName + ".localhost:8011/",//com.web.payment
                    "http://" + tenantName + ".localhost:8002/",//com.webapi.payment
                    "https://" + tenantName + ".localhost:8012/",//com.webapi.payment

                    //微信管理
                    "http://" + tenantName + ".localhost:9001/",//com.web.wechat
                    "https://" + tenantName + ".localhost:9011/",//com.web.wechat
                    "http://" + tenantName + ".localhost:9002/",//com.webapi.wechat
                    "https://" + tenantName + ".localhost:9012/",//com.webapi.wechat

                    //--------------本地开发发布环境：linux/IIS--------------
                    //配置管理
                    "http://" + tenantName + ".localcfg.kcloudy.com/",
                    "http://" + tenantName + ".localcfgapi.kcloudy.com/",
                    "https://" + tenantName + ".localcfg.kcloudy.com/",
                    "https://" + tenantName + ".localcfgapi.kcloudy.com/",
                    //字典管理
                    "http://" + tenantName + ".localdic.kcloudy.com/",
                    "http://" + tenantName + ".localdicapi.kcloudy.com/",
                    "https://" + tenantName + ".localdic.kcloudy.com/",
                    "https://" + tenantName + ".localdicapi.kcloudy.com/",
                    //应用管理
                    "http://" + tenantName + ".localapp.kcloudy.com/",
                    "http://" + tenantName + ".localappapi.kcloudy.com/",
                    "https://" + tenantName + ".localapp.kcloudy.com/",
                    "https://" + tenantName + ".localappapi.kcloudy.com/",
                    //消息管理
                    "http://" + tenantName + ".localmsg.kcloudy.com/",
                    "http://" + tenantName + ".localmsgapi.kcloudy.com/",
                    "https://" + tenantName + ".localmsg.kcloudy.com/",
                    "https://" + tenantName + ".localmsgapi.kcloudy.com/",

                    //账户管理
                    "http://" + tenantName + ".localacc.kcloudy.com/",
                    "http://" + tenantName + ".localaccapi.kcloudy.com/",
                    "https://" + tenantName + ".localacc.kcloudy.com/",
                    "https://" + tenantName + ".localaccapi.kcloudy.com/",
                    //合同管理
                    "http://" + tenantName + ".localecon.kcloudy.com/",
                    "https://" + tenantName + ".localeconapi.kcloudy.com/",
                    "http://" + tenantName + ".localecon.kcloudy.com/",
                    "https://" + tenantName + ".localeconapi.kcloudy.com/",
                    //文档管理
                    "http://" + tenantName + ".localdoc.kcloudy.com/",
                    "http://" + tenantName + ".localdocapi.kcloudy.com/",
                    "https://" + tenantName + ".localdoc.kcloudy.com/",
                    "https://" + tenantName + ".localdocapi.kcloudy.com/",
                    //人事管理
                    "http://" + tenantName + ".localhr.kcloudy.com/",
                    "http://" + tenantName + ".localhrapi.kcloudy.com/",
                    "https://" + tenantName + ".localhr.kcloudy.com/",
                    "https://" + tenantName + ".localhrapi.kcloudy.com/",
                    
                    //客户管理
                    "http://" + tenantName + ".localcrm.kcloudy.com/",
                    "http://" + tenantName + ".localcrmapi.kcloudy.com/",
                    "https://" + tenantName + ".localcrm.kcloudy.com/",
                    "https://" + tenantName + ".localcrmapi.kcloudy.com/",
                    //供应商管理
                    "http://" + tenantName + ".localsrm.kcloudy.com/",
                    "http://" + tenantName + ".localsrmapi.kcloudy.com/",
                    "https://" + tenantName + ".localsrm.kcloudy.com/",
                    "https://" + tenantName + ".localsrmapi.kcloudy.com/",
                    //商品管理
                    "http://" + tenantName + ".localprd.kcloudy.com/",
                    "http://" + tenantName + ".localprdapi.kcloudy.com/",
                    "https://" + tenantName + ".localprd.kcloudy.com/",
                    "https://" + tenantName + ".localprdapi.kcloudy.com/",
                    //物料管理
                    "http://" + tenantName + ".localpmc.kcloudy.com/",
                    "http://" + tenantName + ".localpmcapi.kcloudy.com/",
                    "https://" + tenantName + ".localpmc.kcloudy.com/",
                    "https://" + tenantName + ".localpmcapi.kcloudy.com/",
                    
                    //门户管理
                    "http://" + tenantName + ".local.kcloudy.com/",//com.web.portal
                    "https://" + tenantName + ".local.kcloudy.com/",//com.web.portal
                    "http://" + tenantName + ".localapi.kcloudy.com/",//com.webapi.portal
                    "https://" + tenantName + ".localapi.kcloudy.com/",//com.webapi.portal

                    //培训管理
                    "http://" + tenantName + ".localtrn.kcloudy.com/",//com.web.training
                    "https://" + tenantName + ".localtrn.kcloudy.com/",//com.web.training
                    "http://" + tenantName + ".localtrnapi.kcloudy.com/",//com.webapi.training
                    "https://" + tenantName + ".localtrnapi.kcloudy.com/",//com.webapi.training

                    //流程管理
                    "http://" + tenantName + ".localflow.kcloudy.com/",//com.web.workflow
                    "https://" + tenantName + ".localflow.kcloudy.com/",//com.web.workflow
                    "http://" + tenantName + ".localflowapi.kcloudy.com/",//com.webapi.workflow
                    "https://" + tenantName + ".localflowapi.kcloudy.com/",//com.webapi.workflow
                    //支付管理
                    "http://" + tenantName + ".localpay.kcloudy.com/",//com.web.payment
                    "https://" + tenantName + ".localpay.kcloudy.com/",//com.web.payment
                    "http://" + tenantName + ".localpayapi.kcloudy.com/",//com.webapi.payment
                    "https://" + tenantName + ".localpayapi.kcloudy.com/",//com.webapi.payment

                    //微信管理
                    "http://" + tenantName + ".localwx.kcloudy.com/",//com.web.wechat
                    "https://" + tenantName + ".localwx.kcloudy.com/",//com.web.wechat
                    "http://" + tenantName + ".localwxapi.kcloudy.com/",//com.webapi.wechat
                    "https://" + tenantName + ".localwxapi.kcloudy.com/",//com.webapi.wechat
                };
                #endregion

                case SystemType.Test:
                    #region 测试环境
                    return new[] {
                    //--------------测试环境--------------
                    //配置管理
                    "http://" + tenantName + ".testcfg.kcloudy.com/",
                    "http://" + tenantName + ".testcfgapi.kcloudy.com/",
                    "https://" + tenantName + ".testcfg.kcloudy.com/",
                    "https://" + tenantName + ".testcfgapi.kcloudy.com/",
                    //字典管理
                    "http://" + tenantName + ".testdic.kcloudy.com/",
                    "http://" + tenantName + ".testdicapi.kcloudy.com/",
                    "https://" + tenantName + ".testdic.kcloudy.com/",
                    "https://" + tenantName + ".testdicapi.kcloudy.com/",
                    //应用管理
                    "http://" + tenantName + ".testapp.kcloudy.com/",
                    "http://" + tenantName + ".testappapi.kcloudy.com/",
                    "https://" + tenantName + ".testapp.kcloudy.com/",
                    "https://" + tenantName + ".testappapi.kcloudy.com/",
                    //消息管理
                    "http://" + tenantName + ".testmsg.kcloudy.com/",
                    "http://" + tenantName + ".testmsgapi.kcloudy.com/",
                    "https://" + tenantName + ".testmsg.kcloudy.com/",
                    "https://" + tenantName + ".testmsgapi.kcloudy.com/",
                    
                    //账户管理
                    "http://" + tenantName + ".testacc.kcloudy.com/",
                    "http://" + tenantName + ".testaccapi.kcloudy.com/",
                    "https://" + tenantName + ".testacc.kcloudy.com/",
                    "https://" + tenantName + ".testaccapi.kcloudy.com/",
                    //合同管理
                    "http://" + tenantName + ".testecon.kcloudy.com/",//com.web.contract
                    "https://" + tenantName + ".testeconapi.kcloudy.com/",//com.web.contract
                    "http://" + tenantName + ".testecon.kcloudy.com/",//com.webapi.contract
                    "https://" + tenantName + ".testeconapi.kcloudy.com/",//com.webapi.contract
                    //文档管理
                    "http://" + tenantName + ".testdoc.kcloudy.com/",
                    "http://" + tenantName + ".testdocapi.kcloudy.com/",
                    "https://" + tenantName + ".testdoc.kcloudy.com/",
                    "https://" + tenantName + ".testdocapi.kcloudy.com/",
                    //人事管理
                    "http://" + tenantName + ".testhr.kcloudy.com/",
                    "http://" + tenantName + ".testhrapi.kcloudy.com/",
                    "https://" + tenantName + ".testhr.kcloudy.com/",
                    "https://" + tenantName + ".testhrapi.kcloudy.com/",
                    
                    //客户管理
                    "http://" + tenantName + ".testcrm.kcloudy.com/",
                    "http://" + tenantName + ".testcrmapi.kcloudy.com/",
                    "https://" + tenantName + ".testcrm.kcloudy.com/",
                    "https://" + tenantName + ".testcrmapi.kcloudy.com/",
                    //供应商管理
                    "http://" + tenantName + ".testsrm.kcloudy.com/",
                    "http://" + tenantName + ".testsrmapi.kcloudy.com/",
                    "https://" + tenantName + ".testsrm.kcloudy.com/",
                    "https://" + tenantName + ".testsrmapi.kcloudy.com/",
                    //商品管理
                    "http://" + tenantName + ".testprd.kcloudy.com/",
                    "http://" + tenantName + ".testprdapi.kcloudy.com/",
                    "https://" + tenantName + ".testprd.kcloudy.com/",
                    "https://" + tenantName + ".testprdapi.kcloudy.com/",
                    //物料管理
                    "http://" + tenantName + ".testpmc.kcloudy.com/",
                    "http://" + tenantName + ".testpmcapi.kcloudy.com/",
                    "https://" + tenantName + ".testpmc.kcloudy.com/",
                    "https://" + tenantName + ".testpmcapi.kcloudy.com/",

                    //门户管理
                    "http://" + tenantName + ".test.kcloudy.com/",//com.web.portal
                    "https://" + tenantName + ".test.kcloudy.com/",//com.web.portal
                    "http://" + tenantName + ".test.kcloudy.com/",//com.webapi.portal
                    "https://" + tenantName + ".test.kcloudy.com/",//com.webapi.portal
                    //培训管理
                    "http://" + tenantName + ".testtrn.kcloudy.com/",//com.web.training
                    "https://" + tenantName + ".testtrn.kcloudy.com/",//com.web.training
                    "http://" + tenantName + ".testtrnapi.kcloudy.com/",//com.webapi.training
                    "https://" + tenantName + ".testtrnapi.kcloudy.com/",//com.webapi.training

                    //流程管理
                    "http://" + tenantName + ".testflow.kcloudy.com/",//com.web.workflow
                    "https://" + tenantName + ".testflow.kcloudy.com/",//com.web.workflow
                    "http://" + tenantName + ".testflowapi.kcloudy.com/",//com.webapi.workflow
                    "https://" + tenantName + ".testflowapi.kcloudy.com/",//com.webapi.workflow
                    //支付管理
                    "http://" + tenantName + ".testpay.kcloudy.com/",//com.web.payment
                    "https://" + tenantName + ".testpay.kcloudy.com/",//com.web.payment
                    "http://" + tenantName + ".testpayapi.kcloudy.com/",//com.webapi.payment
                    "https://" + tenantName + ".testpayapi.kcloudy.com/",//com.webapi.payment

                    //微信管理
                    "http://" + tenantName + ".testwx.kcloudy.com/",//com.web.wechat
                    "https://" + tenantName + ".testwx.kcloudy.com/",//com.web.wechat
                    "http://" + tenantName + ".testwxapi.kcloudy.com/",//com.webapi.wechat
                    "https://" + tenantName + ".testwxapi.kcloudy.com/",//com.webapi.wechat
                };
                #endregion

                case SystemType.Beta:
                    #region UAT环境
                    return new[] {
                    //--------------灰度发布环境--------------
                    //配置管理
                    "http://" + tenantName + ".betacfg.kcloudy.com/",
                    "http://" + tenantName + ".betacfgapi.kcloudy.com/",
                    "https://" + tenantName + ".betacfg.kcloudy.com/",
                    "https://" + tenantName + ".betacfgapi.kcloudy.com/",
                    //字典管理
                    "http://" + tenantName + ".betadic.kcloudy.com/",
                    "http://" + tenantName + ".betadicapi.kcloudy.com/",
                    "https://" + tenantName + ".betadic.kcloudy.com/",
                    "https://" + tenantName + ".betadicapi.kcloudy.com/",
                    //应用管理
                    "http://" + tenantName + ".betaapp.kcloudy.com/",
                    "http://" + tenantName + ".betaappapi.kcloudy.com/",
                    "https://" + tenantName + ".betaapp.kcloudy.com/",
                    "https://" + tenantName + ".betaappapi.kcloudy.com/",
                    //消息管理
                    "http://" + tenantName + ".betamsg.kcloudy.com/",
                    "http://" + tenantName + ".betamsgapi.kcloudy.com/",
                    "https://" + tenantName + ".betamsg.kcloudy.com/",
                    "https://" + tenantName + ".betamsgapi.kcloudy.com/",

                    //账户管理
                    "http://" + tenantName + ".betaacc.kcloudy.com/",
                    "http://" + tenantName + ".betaaccapi.kcloudy.com/",
                    "https://" + tenantName + ".betaacc.kcloudy.com/",
                    "https://" + tenantName + ".betaaccapi.kcloudy.com/",
                    //合同管理
                    "http://" + tenantName + ".betaecon.kcloudy.com/",
                    "https://" + tenantName + ".betaeconapi.kcloudy.com/",
                    "http://" + tenantName + ".betaecon.kcloudy.com/",
                    "https://" + tenantName + ".betaeconapi.kcloudy.com/",
                    //文档管理
                    "http://" + tenantName + ".betadoc.kcloudy.com/",
                    "http://" + tenantName + ".betadocapi.kcloudy.com/",
                    "https://" + tenantName + ".betadoc.kcloudy.com/",
                    "https://" + tenantName + ".betadocapi.kcloudy.com/",
                    //人事管理
                    "http://" + tenantName + ".betahr.kcloudy.com/",
                    "http://" + tenantName + ".betahrapi.kcloudy.com/",
                    "https://" + tenantName + ".betahr.kcloudy.com/",
                    "https://" + tenantName + ".betahrapi.kcloudy.com/",
                    
                    //客户管理
                    "http://" + tenantName + ".betacrm.kcloudy.com/",
                    "http://" + tenantName + ".betacrmapi.kcloudy.com/",
                    "https://" + tenantName + ".betacrm.kcloudy.com/",
                    "https://" + tenantName + ".betacrmapi.kcloudy.com/",
                    //供应商管理
                    "http://" + tenantName + ".betasrm.kcloudy.com/",
                    "http://" + tenantName + ".betasrmapi.kcloudy.com/",
                    "https://" + tenantName + ".betasrm.kcloudy.com/",
                    "https://" + tenantName + ".betasrmapi.kcloudy.com/",
                    //商品管理
                    "http://" + tenantName + ".betaprd.kcloudy.com/",
                    "http://" + tenantName + ".betaprdapi.kcloudy.com/",
                    "https://" + tenantName + ".betaprd.kcloudy.com/",
                    "https://" + tenantName + ".betaprdapi.kcloudy.com/",
                    //物料管理
                    "http://" + tenantName + ".betapmc.kcloudy.com/",
                    "http://" + tenantName + ".betapmcapi.kcloudy.com/",
                    "https://" + tenantName + ".betapmc.kcloudy.com/",
                    "https://" + tenantName + ".betapmcapi.kcloudy.com/",
                    
                    //门户管理
                    "http://" + tenantName + ".beta.kcloudy.com/",//com.web.portal
                    "https://" + tenantName + ".beta.kcloudy.com/",//com.web.portal
                    "http://" + tenantName + ".beta.kcloudy.com/",//com.webapi.portal
                    "https://" + tenantName + ".beta.kcloudy.com/",//com.webapi.portal
                    //培训管理
                    "http://" + tenantName + ".betatrn.kcloudy.com/",//com.web.training
                    "https://" + tenantName + ".betatrn.kcloudy.com/",//com.web.training
                    "http://" + tenantName + ".betatrnapi.kcloudy.com/",//com.webapi.training
                    "https://" + tenantName + ".betatrnapi.kcloudy.com/",//com.webapi.training

                    //流程管理
                    "http://" + tenantName + ".betaflow.kcloudy.com/",//com.web.workflow
                    "https://" + tenantName + ".betaflow.kcloudy.com/",//com.web.workflow
                    "http://" + tenantName + ".betaflowapi.kcloudy.com/",//com.webapi.workflow
                    "https://" + tenantName + ".betaflowapi.kcloudy.com/",//com.webapi.workflow
                    //支付管理
                    "http://" + tenantName + ".betapay.kcloudy.com/",//com.web.payment
                    "https://" + tenantName + ".betapay.kcloudy.com/",//com.web.payment
                    "http://" + tenantName + ".betapayapi.kcloudy.com/",//com.webapi.payment
                    "https://" + tenantName + ".betapayapi.kcloudy.com/",//com.webapi.payment

                    //微信管理
                    "http://" + tenantName + ".betawx.kcloudy.com/",//com.web.wechat
                    "https://" + tenantName + ".betawx.kcloudy.com/",//com.web.wechat
                    "http://" + tenantName + ".betawxapi.kcloudy.com/",//com.webapi.wechat
                    "https://" + tenantName + ".betawxapi.kcloudy.com/",//com.webapi.wechat
                    
                };
                #endregion

                default:
                    #region 正式发布环境
                    return new[] {
                    //--------------正式发布环境--------------
                    //配置管理
                    "http://" + tenantName + ".cfg.kcloudy.com/",
                    "http://" + tenantName + ".cfgapi.kcloudy.com/",
                    "https://" + tenantName + ".cfg.kcloudy.com/",
                    "https://" + tenantName + ".cfgapi.kcloudy.com/",
                    //字典管理
                    "http://" + tenantName + ".dic.kcloudy.com/",
                    "http://" + tenantName + ".dicapi.kcloudy.com/",
                    "https://" + tenantName + ".dic.kcloudy.com/",
                    "https://" + tenantName + ".dicapi.kcloudy.com/",
                    //应用管理
                    "http://" + tenantName + ".app.kcloudy.com/",
                    "http://" + tenantName + ".appapi.kcloudy.com/",
                    "https://" + tenantName + ".app.kcloudy.com/",
                    "https://" + tenantName + ".appapi.kcloudy.com/",
                    //消息管理
                    "http://" + tenantName + ".msg.kcloudy.com/",
                    "http://" + tenantName + ".msgapi.kcloudy.com/",
                    "https://" + tenantName + ".msg.kcloudy.com/",
                    "https://" + tenantName + ".msgapi.kcloudy.com/",

                    //账户管理
                    "http://" + tenantName + ".acc.kcloudy.com/",
                    "http://" + tenantName + ".accapi.kcloudy.com/",
                    "https://" + tenantName + ".acc.kcloudy.com/",
                    "https://" + tenantName + ".accapi.kcloudy.com/",
                    //合同管理
                    "http://" + tenantName + ".econ.kcloudy.com/",
                    "https://" + tenantName + ".econapi.kcloudy.com/",
                    "http://" + tenantName + ".econ.kcloudy.com/",
                    "https://" + tenantName + ".econapi.kcloudy.com/",
                    //文档管理
                    "http://" + tenantName + ".doc.kcloudy.com/",
                    "http://" + tenantName + ".docapi.kcloudy.com/",
                    "https://" + tenantName + ".doc.kcloudy.com/",
                    "https://" + tenantName + ".docapi.kcloudy.com/",
                    //人事管理
                    "http://" + tenantName + ".hr.kcloudy.com/",
                    "http://" + tenantName + ".hrapi.kcloudy.com/",
                    "https://" + tenantName + ".hr.kcloudy.com/",
                    "https://" + tenantName + ".hrapi.kcloudy.com/",
                    
                    //客户管理
                    "http://" + tenantName + ".crm.kcloudy.com/",
                    "http://" + tenantName + ".crmapi.kcloudy.com/",
                    "https://" + tenantName + ".crm.kcloudy.com/",
                    "https://" + tenantName + ".crmapi.kcloudy.com/",
                    //供应商管理
                    "http://" + tenantName + ".srm.kcloudy.com/",
                    "http://" + tenantName + ".srmapi.kcloudy.com/",
                    "https://" + tenantName + ".srm.kcloudy.com/",
                    "https://" + tenantName + ".srmapi.kcloudy.com/",
                    //商品管理
                    "http://" + tenantName + ".prd.kcloudy.com/",
                    "http://" + tenantName + ".prdapi.kcloudy.com/",
                    "https://" + tenantName + ".prd.kcloudy.com/",
                    "https://" + tenantName + ".prdapi.kcloudy.com/",
                    //物料管理
                    "http://" + tenantName + ".pmc.kcloudy.com/",
                    "http://" + tenantName + ".pmcapi.kcloudy.com/",
                    "https://" + tenantName + ".pmc.kcloudy.com/",
                    "https://" + tenantName + ".pmcapi.kcloudy.com/",

                    //门户管理
                    "http://" + tenantName + ".kcloudy.com/",//com.web.portal
                    "https://" + tenantName + ".kcloudy.com/",//com.web.portal
                    "http://" + tenantName + ".kcloudy.com/",//com.webapi.portal
                    "https://" + tenantName + ".kcloudy.com/",//com.webapi.portal
                    //培训管理
                    "http://" + tenantName + ".trn.kcloudy.com/",//com.web.training
                    "https://" + tenantName + ".trn.kcloudy.com/",//com.web.training
                    "http://" + tenantName + ".trnapi.kcloudy.com/",//com.webapi.training
                    "https://" + tenantName + ".trnapi.kcloudy.com/",//com.webapi.training

                    //流程管理
                    "http://" + tenantName + ".flow.kcloudy.com/",//com.web.workflow
                    "https://" + tenantName + ".flow.kcloudy.com/",//com.web.workflow
                    "http://" + tenantName + ".flowapi.kcloudy.com/",//com.webapi.workflow
                    "https://" + tenantName + ".flowapi.kcloudy.com/",//com.webapi.workflow
                    //支付管理
                    "http://" + tenantName + ".pay.kcloudy.com/",//com.web.payment
                    "https://" + tenantName + ".pay.kcloudy.com/",//com.web.payment
                    "http://" + tenantName + ".payapi.kcloudy.com/",//com.webapi.payment
                    "https://" + tenantName + ".payapi.kcloudy.com/",//com.webapi.payment

                    //微信管理
                    "http://" + tenantName + ".wx.kcloudy.com/",//com.web.wechat
                    "https://" + tenantName + ".wx.kcloudy.com/",//com.web.wechat
                    "http://" + tenantName + ".wxapi.kcloudy.com/",//com.webapi.wechat
                    "https://" + tenantName + ".wxapi.kcloudy.com/",//com.webapi.wechat
                };
                    #endregion
            }
        }
        #endregion
        #endregion

        #region 获取配置的链接字符串，形如：Tuple<Server, DataBase, ConnectionPasswordHash>

        #region 获取测试租户的数据库连接字符串
        public const DatabaseType DefaultDatabaseType = DatabaseType.SqlServer;
        public static string DefaultPrivateEncryptKey { get; private set; }
        public static string DefaultDatabaseConnectionString { get; private set; }

        /// <summary>
        /// 获取数据库服务器的连接信息：Tuple<server, database, password>
        /// </summary>
        /// <param name="isEncrypPassword">是否将数据库登录密码进行加密处理：秘钥为配置文件中的EncryptKey</param>
        /// <returns></returns>
        public static Tuple<string, string, string> GetDatabaseConnectionItems(bool isEncrypPassword = true)
        {
            var conntionString = DefaultDatabaseConnectionString;
            var dicCon = conntionString.KeyValuePairFromConnectionString();
            var passwordHash = isEncrypPassword ?
                SecurityHelper.EncryptPasswordUtil.EncryptPassword("P@ssw0rd", DefaultPrivateEncryptKey)
                : "P@ssw0rd";

            var server = string.Empty;
            if (dicCon.ContainsKey("server"))
            {
                server = dicCon["server"];
            }
            else if (dicCon.ContainsKey("data source"))
            {
                server = dicCon["data source"];
            }

            var database = string.Empty;
            if (dicCon.ContainsKey("database"))
            {
                database = dicCon["database"];
            }

            return new Tuple<string, string, string>(server, database, passwordHash);
        }
        #endregion

        #region 获取测试租户的存储连接字符串
        public const StorageType DefaultStorageType = StorageType.Blob;
        public static string DefaultStorageConnectionString { get; private set; }
        /// <summary>
        /// 获取存储服务器的连接信息：Tuple<endpont, accessName, accessKey>
        /// </summary>
        /// <param name="isEncrypPassword">是否将存储服务器的访问秘钥进行加密处理：加密Key为配置文件中的EncryptKey</param>
        /// <returns></returns>
        public static Tuple<string, string, string> GetStorageConnectionItems(bool isEncrypPassword = true)
        {
            var endpont = string.Empty;
            var accessName = string.Empty;
            var accessKey = string.Empty;

            var dataConnString = DefaultStorageConnectionString;
            var keyValues = dataConnString.KeyValuePairFromConnectionString();
            endpont = keyValues[ConnectionKeyConstant.BlobEndpoint];
            accessName = keyValues[ConnectionKeyConstant.AccessName];
            accessKey = keyValues[ConnectionKeyConstant.AccessKey];
            var encryptKey = isEncrypPassword
                ? SecurityHelper.EncryptPasswordUtil.EncryptPassword(accessKey, DefaultPrivateEncryptKey)
                : accessKey;

            return new Tuple<string, string, string>(endpont, accessName, encryptKey);
        }
        #endregion

        #region 获取测试租户的队列连接字符串
        public const QueueType DefaultQueueType = QueueType.AzureQueue;
        public static string DefaultQueueConnectionString { get; private set; }
        /// <summary>
        /// 获取队列服务器的连接信息：Tuple<endpont, accessName, accessKey>
        /// </summary>
        /// <param name="isEncrypPassword">是否将队列服务器的访问秘钥进行加密处理：加密Key为配置文件中的EncryptKey</param>
        /// <returns></returns>
        public static Tuple<string, string, string> GetQueueConnectionItems(bool isEncrypPassword = true)
        {
            var endpont = string.Empty;
            var accessName = string.Empty;
            var accessKey = string.Empty;

            var dataConnString = DefaultQueueConnectionString;
            var keyValues = dataConnString.KeyValuePairFromConnectionString();
            endpont = keyValues[ConnectionKeyConstant.QueueEndpoint];
            accessName = keyValues[ConnectionKeyConstant.AccessName];
            accessKey = keyValues[ConnectionKeyConstant.AccessKey];
            var encryptKey = isEncrypPassword
                ? SecurityHelper.EncryptPasswordUtil.EncryptPassword(accessKey, DefaultPrivateEncryptKey)
                : accessKey;

            return new Tuple<string, string, string>(endpont, accessName, encryptKey);
        }
        #endregion

        #region 获取测试租户的noSql连接字符串
        public const NoSqlType DefaultNoSqlType = NoSqlType.AzureTable;
        public static string DefaultNoSqlConnectionString { get; private set; }
        /// <summary>
        /// 获取NoSql服务器的连接信息：Tuple<endpont, accessName, accessKey>
        /// </summary>
        /// <param name="isEncrypPassword">是否将NoSql服务器的访问秘钥进行加密处理：加密Key为配置文件中的EncryptKey</param>
        /// <returns></returns>
        public static Tuple<string, string, string> GetNoSqlConnectionItems(bool isEncrypPassword = true)
        {
            var endpont = string.Empty;
            var accessName = string.Empty;
            var accessKey = string.Empty;

            var dataConnString = DefaultNoSqlConnectionString;
            var keyValues = dataConnString.KeyValuePairFromConnectionString();
            endpont = keyValues[ConnectionKeyConstant.NoSqlEndpoint];
            accessName = keyValues[ConnectionKeyConstant.AccessName];
            accessKey = keyValues[ConnectionKeyConstant.AccessKey];
            var encryptKey = isEncrypPassword
                ? SecurityHelper.EncryptPasswordUtil.EncryptPassword(accessKey, DefaultPrivateEncryptKey)
                : accessKey;

            return new Tuple<string, string, string>(endpont, accessName, encryptKey);
        }
        #endregion

        #region 获取测试租户的noSql连接字符串
        public const DistributedMessageType DefaultServiceBusType = DistributedMessageType.ServiceBus;
        public static string DefaultServiceBusConnectionString { get; private set; }
        /// <summary>
        /// 获取分布式服务服务器的连接信息：Tuple<endpont, accessName, accessKey>
        /// </summary>
        /// <param name="isEncrypPassword">是否将分布式服务服务器的访问秘钥进行加密处理：加密Key为配置文件中的EncryptKey</param>
        /// <returns></returns>
        public static Tuple<string, string, string> GetServiceBusConnectionItems(bool isEncrypPassword = true)
        {
            var endpont = string.Empty;
            var accessName = string.Empty;
            var accessKey = string.Empty;

            var dataConnString = DefaultServiceBusConnectionString;
            var keyValues = dataConnString.KeyValuePairFromConnectionString();
            endpont = keyValues[ConnectionKeyConstant.ServiceBusEndpoint];
            accessName = keyValues[ConnectionKeyConstant.ServiceBusAccessName];
            accessKey = keyValues[ConnectionKeyConstant.ServiceBusAccessKey];
            var encryptKey = isEncrypPassword
                ? SecurityHelper.EncryptPasswordUtil.EncryptPassword(accessKey, DefaultPrivateEncryptKey)
                : accessKey;

            return new Tuple<string, string, string>(endpont, accessName, encryptKey);
        }
        #endregion
        #endregion

        public static string GetClientIdByTenant(Tenant tenant)
        {
            if (string.IsNullOrEmpty(tenant.TenantName))
                return string.Empty;

            return Base64Provider.EncodeBase64String(tenant.TenantName);
        }
        public static string GetClientSecretByTenant(Tenant tenant)
        {
            if (string.IsNullOrEmpty(tenant.TenantName))
                return string.Empty;

            var key = tenant.TenantName.ToLower() + ":" + tenant.PrivateEncryptKey;
            var md5Key = MD5Provider.Hash(key);

            return Base64Provider.EncodeBase64String(md5Key);

            //return Sha256(tenant.TenantName.ToLower() + ":" + tenant.PrivateEncryptKey);
        }

        /// <summary>
        /// Creates a SHA256 hash of the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>A hash</returns>
        public static string Sha256(string input)
        {
            if (string.IsNullOrEmpty(input)) return string.Empty;

            using (var sha = System.Security.Cryptography.SHA256.Create())
            {
                var bytes = System.Text.Encoding.UTF8.GetBytes(input);
                var hash = sha.ComputeHash(bytes);

                return Convert.ToBase64String(hash);
            }
        }

        /// <summary>
        /// Creates a SHA512 hash of the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>A hash</returns>
        public static string Sha512(string input)
        {
            if (string.IsNullOrEmpty(input)) return string.Empty;

            using (var sha = System.Security.Cryptography.SHA512.Create())
            {
                var bytes = System.Text.Encoding.UTF8.GetBytes(input);
                var hash = sha.ComputeHash(bytes);

                return Convert.ToBase64String(hash);
            }
        }

        public static string GetEncodeClientId(string encodeClientId)
        {
            if (string.IsNullOrEmpty(encodeClientId))
                return string.Empty;

            return Base64Provider.EncodeBase64String(encodeClientId);
        }

        public static string GetDecodeClientId(string encodeClientId)
        {
            if (string.IsNullOrEmpty(encodeClientId))
                return string.Empty;
            try
            {
                var clientId = Base64Provider.DecodeBase64String(encodeClientId);
                return clientId;
            }
            catch
            {
                return encodeClientId;
            }
        }
    }
}